package kr.hyunist.androidcomplete01saeildamil.ch19;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class ThreadHadlerEx04 extends Activity {
	int mMainValue = 0;
	int mBackValue = 0;
	TextView mMainText;
	TextView mBackText;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.threadtest01);
		
		mMainText = (TextView) findViewById(R.id.threadtesttv1);
		mBackText = (TextView) findViewById(R.id.threadtesttv2);
		
		BackRunnable br = new BackRunnable();
		Thread th = new Thread(br);
		th.setDaemon(true);
		th.start();
	}
	
	public void mOnClick(View v){
		mMainValue++;
		mMainText.setText("MainValue : " + mMainValue);
	}
	
	/*class BackThread extends Thread {

		@Override
		public void run() {
			while(true){
				mBackValue++;
				mH.post(new Runnable() {
					
					@Override
					public void run() {
						mBackText.setText("BackValue : " + mBackValue);
					}
					
				});
				try {
					Thread.sleep(1000);
				} catch(InterruptedException e){
					e.getStackTrace();
				}
			}
		}
		
	}*/
	
	class BackRunnable implements Runnable {

		@Override
		public void run() {
			while(true){
				mBackValue++;
				mH.post(new Runnable() {
					
					@Override
					public void run() {
						mBackText.setText("BackValue : " + mBackValue);
					}
					
				});
			}
		}
		
	}
	
	Handler mH = new Handler();

}
